package xutil

import (
	"image/color"

	"github.com/mojocn/base64Captcha"
)

// 设置自带的store
var store = base64Captcha.DefaultMemStore

// 生成验证码,新的多了一个answer后续使用中需要测试一下
func F创建图片验证码() (id, b64s, answer string, err error) {
	var driver base64Captcha.Driver
	var driverString base64Captcha.DriverString

	// 配置验证码信息
	captchaConfig := base64Captcha.DriverString{
		Height:          50,
		Width:           120,
		NoiseCount:      0,
		ShowLineOptions: 2 | 4,
		Length:          3,
		Source:          "1234567890",
		BgColor: &color.RGBA{
			R: 3,
			G: 102,
			B: 214,
			A: 125,
		},
		Fonts: []string{"wqy-microhei.ttc"},
	}

	driverString = captchaConfig
	driver = driverString.ConvertFonts()
	captcha := base64Captcha.NewCaptcha(driver, store)
	captcha.Generate()
	lid, lb64s, answer, lerr := captcha.Generate()
	//生成后存进缓存，并且应该绑定一下是否为当前IP的吧。
	return lid, lb64s, answer, lerr
}

// 验证captcha是否正确,id 验证码ID，capt是验证码
func F验证验证码(id string, capt string) bool {
	//这里要判断一下这个codeid是否为当前用户的，是否过期
	return store.Verify(id, capt, true)
}
